package com.panopset.db;

import java.io.StringWriter;


/**
 * Varchar field.
 * @author Karl Dinwiddie
 *
 */
public final class FieldVarchar extends DataField {

    /**
     * Varchar maximum size.
     */
    private final int size;

    /**
     * @param name Name.
     * @param length Length.
     */
    public FieldVarchar(final String name, final int length) {
        super(name);
        size = length;
    }

    @Override
    public String getAttributes() {
        if (attrs == null) {
            StringWriter sw = new StringWriter();
            sw.append("varchar(" + size);
            sw.append(")");
            attrs = sw.toString();
        }
        return attrs;
    }

    /**
     * @return Size.
     */
    public int getSize() {
        return size;
    }

    /**
     * Attributes.
     */
    private String attrs;
}
